package com.ihome.android.market2.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ScrollView;

public class MyScrollView extends ScrollView {

	private String			TAG	= MyScrollView.class.getSimpleName();

	private ScrollListener	scrollListener;

	public MyScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		super.onScrollChanged(l, t, oldl, oldt);

		Log.d(TAG, "getTotalVerticalScrollRange = " + getTotalVerticalScrollRange());
		Log.d(TAG, "getScrollY = " + getScrollY());
		Log.d(TAG, "getHeight = " + getHeight());
		if (getScrollY() + getHeight() >= computeVerticalScrollRange()) {
			//Log.d(TAG, "------滚动到最下方------");
			scrollListener.scrolltobottom();
		}else if(getScrollY() == 0){
			scrollListener.scrolltoTop();
		}
		else {
			//Log.d(TAG, "没有到最下方");
		}
	}

	public void setScrollListener(ScrollListener scrollListener) {
		this.scrollListener = scrollListener;
	}

	public interface ScrollListener {
		public void scrolltobottom();
		public void scrolltoTop();
	}

	public int getTotalVerticalScrollRange() {
		return super.computeVerticalScrollRange();
	}

}
